<?php
header("Content-type: text/html; charset=utf-8");
ini_set('display_errors',1);
set_time_limit(0); 
include_once  dirname(dirname(dirname(__FILE__))).'/mgtv_init.php';
define('ORG_ID', 'xjdx_zte');
include_once  dirname(dirname(dirname(__FILE__))) . '/'.ORG_ID.'/init.php';
include_once dirname(dirname(dirname(__FILE__))) .'/models/queue_task_model.php';

class get_task extends nn_timer
{
	public function action($params = null)
	{
		$this->msg('开始执行...');
		do_timer_action();
		$this->msg('执行结束...');
	}
}
$get_task = new get_task("get_task", ORG_ID);
$get_task->run();

function do_timer_action()
{
	i_echo('start');
	$sp_config = sp_model::get_sp_config(ORG_ID);
	if(isset($sp_config['op_pre_max'])&&(int)$sp_config['op_pre_max']>0){
		$max_num = $sp_config['op_pre_max'];
	}else{
		$max_num = 30;
	}
	
	echo $max_num;echo '-------';
	$db = nn_get_db(NL_DB_READ);
	$query_str = "and nns_epg_status=97 and nns_status in (0,1,5)  ";
	$sql_cont = "select count(*) as num from nns_mgtvbk_c2_task where nns_org_id='".ORG_ID."'	$query_str";
	$num = nl_db_get_col($sql_cont, $db);

	echo $num;echo '+++++++++';
	//if($max_num>$num){
	$queue_task_model = new queue_task_model();
	$query_num = $max_num-$num;
	if($query_num>0){
		$queue_task_model->q_get_task(ORG_ID,1000);
	}
	//}
	unset($queue_task_model,$sp_config);
	i_echo('end');
}
